﻿
new Vue({
    el: "#app",
    data: {
        roleMenu: {
            open: false,
            roleID: 0
        },
        sysRoleMenuParam: {
            keyName: 'ID',
            parentName: 'ParentId',
            titleName: 'Name',
            toggleOnSelect: true,
            dataMode: 'list',
            datas: []
        },
        modal: {
            closeOnMask: false
        },
        pageData: [],
        queryParms: {
            Name: "",
        },
        pageDataUrl: "SysRole/pageListData",
        model: {
            SysRole_ID: 0,
            SysMenu_ID: []
        }
    },
    methods: {
        onSearch() {
            this.$refs.tableService.loadData();
        },
        onDataChange(data) {
            this.pageData = data;
        },
        onAdd() {
            location.href = "SysRoleEdit.html";
        },
        onEdit(id) {
            location.href = "SysRoleEdit.html?id=" + id;
        },
        //加载权限菜单
        loadSysRoleMenuData(id) {
            var _this = this;
            this.roleMenu.open = true;
            $http.post("SysRole/MenuAttribute/listData", { SysRole_ID: id }, function (data) {
                _this.sysRoleMenuParam.datas = data.SysMenu;
                var sid = data.MenuAttribute.map(m => m.SysMenu_ID);
                setTimeout(function () {
                    _this.$refs.sysRoleMenu.expandAll();
                    if (sid.length > 0) {
                        _this.$refs.sysRoleMenu.updateChoose(sid);
                    }
                }, 100)
            })
        },
        //选中权限
        onSysRoleSelected() {
            var _this = this;
            var data = this.$refs.sysRoleMenu.getFullChoose();
            var ids = data.map(m => m.ID);
            this.model.SysMenu_ID = ids;
            $http.post("SysRole/SetSysRoleMenuAttribute", this.model, function (d, code, msg) {
                _this.$Message("保存成功");
            });

        },
        onPermission(id) {
            this.model.SysRole_ID = id;
            this.loadSysRoleMenuData(id);
        }
    }
})